home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Day Cry
/
Day Cry CD.bin
/
oh_towns
/
taropyon
/
silib
/
silib.lzh
/
PRG
/
SDKFS
/
FSELSORT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-23
|
9KB
|
375 lines
/*************************************************************************
* â\ü[âg
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sdkfs.h"
#include "sdkfscf.h"
static int SortDir; /* â\ü[âgò√îⁿ */
#define _DIRWORK { \
if ( (*fndat1)->buf.name[0] == '.' ) \
{ if ( (*fndat2)->buf.name[0] == '.' ) \
return strcmp( (*fndat1)->buf.name, (*fndat2)->buf.name); \
else \
return (-1); \
} else if ( (*fndat2)->buf.name[0] == '.' ) \
return (1); \
}
#define ISDIR(_att) ((_att)&FSATT_DIR)
#define _DIRTOP { \
if ( ISDIR((*fndat1)->buf.attrib) ) \
{ if ( !ISDIR((*fndat2)->buf.attrib) ) \
return (-1); \
} else if ( ISDIR((*fndat2)->buf.attrib) ) \
return (1); \
}
#define _DIRLAST { \
if ( ISDIR((*fndat1)->buf.attrib) ) \
{ if ( !ISDIR((*fndat2)->buf.attrib) ) \
return (1); \
} else if ( ISDIR((*fndat2)->buf.attrib) ) \
return (-1); \
}
/*************************************************************************
* âtâ@âCâïû╝â\ü[âg
*************************************************************************/
/* âfâBâîâNâgâèɵô¬ */
static int cmpFunc_fnam_0( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRTOP;
if ( (ret = strcmp( (*fndat1)->buf.name, (*fndat2)->buf.name)) != 0 )
{ if ( SortDir )
return (ret > 0 ? -1: 1); /* ït */
else
return (ret);
} else
return (0);
}
/* âfâBâîâNâgâèûûö÷ */
static int cmpFunc_fnam_1( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRLAST;
if ( (ret = strcmp( (*fndat1)->buf.name, (*fndat2)->buf.name)) != 0 )
{ if ( SortDir )
return (ret > 0 ? -1: 1); /* ït */
else
return (ret);
} else
return (0);
}
/* âfâBâîâNâgâèû│Äï */
static int cmpFunc_fnam_2( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
if ( (ret = strcmp( (*fndat1)->buf.name, (*fndat2)->buf.name)) != 0 )
{ if ( SortDir )
return (ret > 0 ? -1: 1); /* ït */
else
return (ret);
} else
return (0);
}
/*************************************************************************
* ègÆúÄqâ\ü[âg
*************************************************************************/
static CONST char *sub_name( CONST char *filename )
{
if ( ( filename = strrchr(filename,'.') ) == 0 )
return ("");
return (filename + 1);
}
/* âfâBâîâNâgâèɵô¬ */
static int cmpFunc_sub_0( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRTOP;
if ( (ret = strcmp( sub_name((*fndat1)->buf.name), sub_name((*fndat2)->buf.name))) == 0 )
{ if ( (ret = strcmp( (*fndat1)->buf.name, (*fndat2)->buf.name)) == 0 )
return (0);
}
if ( SortDir )
return (ret > 0 ? -1: 1);
else
return (ret);
}
/* âfâBâîâNâgâèûûö÷ */
static int cmpFunc_sub_1( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRLAST;
if ( (ret = strcmp( sub_name((*fndat1)->buf.name), sub_name((*fndat2)->buf.name))) == 0 )
{ if ( (ret = strcmp( (*fndat1)->buf.name, (*fndat2)->buf.name)) == 0 )
return (0);
}
if ( SortDir )
return (ret > 0 ? -1: 1);
else
return (ret);
}
/* âfâBâîâNâgâèû│Äï */
static int cmpFunc_sub_2( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
if ( (ret = strcmp( sub_name((*fndat1)->buf.name), sub_name((*fndat2)->buf.name))) == 0 )
{ if ( (ret = strcmp( (*fndat1)->buf.name, (*fndat2)->buf.name)) == 0 )
return (0);
}
if ( SortDir )
return (ret > 0 ? -1: 1);
else
return (ret);
}
/*************************************************************************
* â^âCâÇâXâ^âôâv
*************************************************************************/
/* âfâBâîâNâgâèɵô¬ */
static int cmpFunc_date_0( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRTOP;
# define VT unsigned short int
if ( (ret = (int)((VT)(*fndat1)->buf.wr_date - (VT)(*fndat2)->buf.wr_date)) == 0 )
{ if ( (ret = (int)((VT)(*fndat1)->buf.wr_time - (VT)(*fndat2)->buf.wr_time)) == 0 )
return (0);
}
# undef VT
if ( SortDir )
return (ret > 0 ? -1: 1);
else
return (ret);
}
/* âfâBâîâNâgâèûûö÷ */
static int cmpFunc_date_1( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRLAST;
# define VT unsigned short int
if ( (ret = (int)((VT)(*fndat1)->buf.wr_date - (VT)(*fndat2)->buf.wr_date)) == 0 )
{ if ( (ret = (int)((VT)(*fndat1)->buf.wr_time - (VT)(*fndat2)->buf.wr_time)) == 0 )
return (0);
}
# undef VT
if ( SortDir )
return (ret > 0 ? -1: 1);
else
return (ret);
}
/* âfâBâîâNâgâèû│Äï */
static int cmpFunc_date_2( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
# define VT unsigned short int
if ( (ret = (int)((VT)(*fndat1)->buf.wr_date - (VT)(*fndat2)->buf.wr_date)) == 0 )
{ if ( (ret = (int)((VT)(*fndat1)->buf.wr_time - (VT)(*fndat2)->buf.wr_time)) == 0 )
return (0);
}
# undef VT
if ( SortDir )
return (ret > 0 ? -1: 1);
else
return (ret);
}
/*************************************************************************
* âtâ@âCâïâTâCâY
*************************************************************************/
/* âfâBâîâNâgâèɵô¬ */
static int cmpFunc_size_0( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRTOP;
if ( ISDIR((*fndat1)->buf.attrib) && ISDIR((*fndat2)->buf.attrib) )
return (0);
if ( (ret = (int)(*fndat1)->buf.size - (int)(*fndat2)->buf.size) == 0 )
return (0);
if ( SortDir )
return (ret > 0 ? -1: 1);
else
return (ret);
}
/* âfâBâîâNâgâèûûö÷ */
static int cmpFunc_size_1( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRLAST;
if ( ISDIR((*fndat1)->buf.attrib) && ISDIR((*fndat2)->buf.attrib) )
return (0);
if ( (ret = (int)(*fndat1)->buf.size - (int)(*fndat2)->buf.size) == 0 )
return (0);
if ( SortDir )
return (ret > 0 ? -1: 1);
else
return (ret);
}
/* âfâBâîâNâgâèû│Äï */
static int cmpFunc_size_2( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
if ( ISDIR((*fndat1)->buf.attrib) && ISDIR((*fndat2)->buf.attrib) )
return (0);
if ( (ret = (int)(*fndat1)->buf.size - (int)(*fndat2)->buf.size) == 0 )
return (0);
if ( SortDir )
return (ret > 0 ? -1: 1);
else
return (ret);
}
/*************************************************************************
* â\ü[âgâIât
*************************************************************************/
/* âfâBâîâNâgâèɵô¬ */
static int cmpFunc_off_0( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRTOP;
if ( (ret = (*fndat1)->no - (*fndat2)->no) == 0 )
return (0);
if ( SortDir )
return (ret > 0 ? -1 : 1);
else
return (ret);
}
/* âfâBâîâNâgâèûûö÷ */
static int cmpFunc_off_1( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
_DIRLAST;
if ( (ret = (*fndat1)->no - (*fndat2)->no) == 0 )
return (0);
if ( SortDir )
return (ret > 0 ? -1 : 1);
else
return (ret);
}
/* âfâBâîâNâgâèû│Äï */
static int cmpFunc_off_2( FNDAT_T **fndat1, FNDAT_T **fndat2 )
{
int ret;
_DIRWORK;
if ( (ret = (*fndat1)->no - (*fndat2)->no) == 0 )
return (0);
if ( SortDir )
return (ret > 0 ? -1 : 1);
else
return (ret);
}
/*************************************************************************
* â\ü[âgâïü[â`âô
*************************************************************************/
void FileSel_sort( FILESEL_T *fs )
{
int (*func)( FNDAT_T **, FNDAT_T **);
if ( fs->numMat == 0 || fs->fnMat == NULL )
return;
SortDir = (fs->sort & FSSORT_RVS) == 0 ? FALSE : TRUE;
switch ( fs->sort & 0x0F )
{
case FSSORT_FILE:
switch ( fs->sort & FSSORT_DIRBIT )
{ case FSSORT_DIRTOP: func = cmpFunc_fnam_0; break;
case FSSORT_DIRLAST: func = cmpFunc_fnam_1; break;
case FSSORT_DIROFF: func = cmpFunc_fnam_2; break;
}
break;
case FSSORT_SUB:
switch ( fs->sort & FSSORT_DIRBI